//
//  MTTypeButtonView.m
//  carcareIOS
//
//  Created by wr on 15/10/16.
//  Copyright (c) 2015年 baozun. All rights reserved.
//

#import "MTTypeButtonView.h"

@interface MTTypeButtonView()

@property (nonatomic , strong) UIView * orangeLineView;

@property (nonatomic , strong) UIColor * changeColor;

@property (nonatomic , strong) UIColor * normallTextColor;

@end

@implementation MTTypeButtonView

- (instancetype)initWithFrame:(CGRect)frame withChangeColor:(UIColor *)changeColor
{
    self = [super initWithFrame:frame];
    if (self) {
        self.changeColor = changeColor;
        self.normallTextColor = COLOR_HEXSTRING(@"#949494");
        
        CGFloat buttonW = __MAIN_WIDTH / 2;
        
        self.smallButton =[[UIButton buttonWithFrame:CGRectMake(0, 0, buttonW, self.frame.size.height) title:@"小保养" textColor:self.normallTextColor  font:FONT_BUTTON click:nil] setupOnView:self];
        self.smallButton.tag = 14;
        self.smallButton.titleLabel.font = FONT_DEFAULT_Light(15);
        [self.smallButton setBackgroundImage:[ImageHelper imageWithSolidColor:[[UIColor blackColor] colorWithAlphaComponent:0.1] size:CGSizeMake(5, 5)] forState:UIControlStateHighlighted];
        
        self.bigButton = [[UIButton buttonWithFrame:CGRectMake(buttonW, 0, buttonW, self.frame.size.height)  title:@"大保养" textColor:self.normallTextColor font:FONT_BUTTON click:nil] setupOnView:self];
        
        self.bigButton.tag = 15;
        self.bigButton.titleLabel.font = FONT_DEFAULT_Light(15);
        [self.bigButton setBackgroundImage:[ImageHelper imageWithSolidColor:[[UIColor blackColor] colorWithAlphaComponent:0.1] size:CGSizeMake(5, 5)] forState:UIControlStateHighlighted];
        
        CGFloat lineH =  15;
        CGFloat lineY = (self.frame.size.height - lineH) / 2;
       
        [[[UIView viewWithFrame:CGRectMake(buttonW, lineY, 0.5, lineH)] resetBackgroundColor:COLOR_HEXSTRING(@"#D7D7D7")] setupOnView:self];
        [[[UIView viewWithFrame:CGRectMake(0, self.frame.size.height - 0.5, self.frame.size.width, 0.5)] resetBackgroundColor:COLOR_HEXSTRING(@"#D7D7D7")] setupOnView:self];
        [[[UIView viewWithFrame:CGRectMake(0, 0, self.frame.size.width, 0.5)] resetBackgroundColor:COLOR_HEXSTRING(@"#D7D7D7")] setupOnView:self];
        self.orangeLineView = [[[UIView viewWithFrame:CGRectMake(0, self.frame.size.height - 3, buttonW, 3)] resetBackgroundColor:self.changeColor] setupOnView:self];
        self.orangeLineView.hidden = YES;

    }
    return self;
}
- (void)choiceButtonChange:(UIButton *)sender
{
    [self.smallButton setTitleColor:self.normallTextColor forState:UIControlStateNormal];
    [self.bigButton setTitleColor:self.normallTextColor forState:UIControlStateNormal];
    
    self.orangeLineView.hidden = NO;
    
    if (sender == self.smallButton) {
        [self.smallButton setTitleColor:self.changeColor forState:UIControlStateNormal];
        [self.orangeLineView setLeft:0];
    }
    if (sender == self.bigButton) {
        [self.bigButton setTitleColor:self.changeColor forState:UIControlStateNormal];
        [self.orangeLineView setLeft:self.bigButton.origin.x];
    }
}
@end
